package ar.com.commsys.ya.estoy;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.location.Location;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class AquiEstoyOverlay extends Overlay {

	//un comentario
	Location location;
	public Location getLocation() { return location; }
	public void setLocation(Location location) { this.location = location; }
	
	private final int mRadius = 10;
	
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
	
		//Utilidad para convertir unidad geo a pixels y viceversa
		Projection projection = mapView.getProjection();
		if (shadow == false && location!=null) {
			
			// Ubicacion geografica
			Double latitude = location.getLatitude()*1E6; 
			Double longitude = location.getLongitude()*1E6; 
			GeoPoint geoPoint;
			geoPoint = new GeoPoint(latitude.intValue(),longitude.intValue());
		
			// Ubicacion en screen pixels 
			Point point = new Point(); 
			projection.toPixels(geoPoint, point);

			// Creacion del paint frente
			Paint paint = new Paint(); 
			paint.setARGB(250, 255, 255, 255); //Alpha RGB (blanco)
			paint.setAntiAlias(true); 
			paint.setFakeBoldText(true);
			
			//Limite Rectangular (left, top, right, bottom)
			RectF oval = new RectF(point.x - mRadius, point.y - mRadius, point.x + mRadius, point.y + mRadius);

			// Dibujo el marcador
			canvas.drawOval(oval, paint);
			
			// Creacion del paint fondo
			Paint backPaint = new Paint(); 
			backPaint.setARGB(175, 50, 50, 50); //Alpha RGB (gris)
			backPaint.setAntiAlias(true);
			
			//Limite Rectangular (left, top, right, bottom)
			RectF backRect = new RectF(point.x + 7, point.y - 15, point.x + 90, point.y + 5);
		
			//Rectangulo de fondo
			canvas.drawRoundRect(backRect, mRadius, mRadius, backPaint); 
			
			//Leyenda
			canvas.drawText("Aqui estoy", point.x + 2*mRadius, point.y, paint);		
		}
		super.draw(canvas, mapView, shadow); 
	}

	@Override
	public boolean onTap(GeoPoint arg0, MapView arg1) {
		// TODO Auto-generated method stub
		return super.onTap(arg0, arg1);
	}

}
